;(function(global) {
  global.submit = {
    template: `
              <div class="submit">
                <div class="submit-container">
                  <div class="flex-wrap flex-justify-center flex-center-wrap submit-top">
                    <div class="submit-top-icon">
                      <img class="submit-trophy" src="./image/exercise/cup.png" alt="">
                    </div>
                    <div class="submit-top-test-info">
                      <div><span class="submit-top-score">{{ testGetScore }}</span></div>
                      <div class="submit-top-test-info-title">本次得分</div>
                    </div>
                  </div>
                  <div class="submit-slogan-container">
                    <span class="submit-slogan">{{ encourage }}</span>
                  </div>
                  <div class="flex-wrap flex-justify-between flex-center-wrap submit-test-result">
                    <div>满分：{{ totalScore }}分</div>
                    <div class="submit-interval"></div>
                    <div>正确率：{{ rightRate }}%</div>
                    <div class="submit-interval"></div>
                    <div>用时：{{ handleTimeCost }}</div>
                  </div>
                  <!-- 中间选项部分 -->
                  <zl-sheet 
                    @swipeto="swipeTo"
                    :exam-data="examData"
                    :parts="parts"
                    :where="1"
                    :type="true"
                    >
                  </zl-sheet>
                </div>
                <!-- 底部 -->
                <div class="flex-wrap flex-justify-center flex-center-wrap submit-bottom">
                  <div class="submit-look-analysis" @click="viewAnalysis">查看解析</div>
                  <div class="submit-test-agin" @click="testAgain">再考一次</div>
                </div>
              </div>
          `,
    props: [
      'examData',
      'parts',
      'handleTimeCost',
      'queryObj',
      'noJudegeScore',
      'getEncourageAgain',
      'encourage'
    ],
    components: {
      'zl-sheet': sheet
    },
    data() {
      return {}
    },
    watch: {},
    computed: {
      // 试卷总分
      totalScore() {
        let num = 0
        for (let item of this.parts) {
          num += Number(item.scoresum)
        }
        return num
      },
      // 正确率
      rightRate() {
        let rate = 0
        rate = Math.round((this.testGetScore / this.totalScore) * 100) || 0
        if (rate < 0) {
          rate = 0
        }
        return rate
      },
      // 本次得分
      testGetScore() {
        let getScore = 0
        let deductScore = 0
        for (let item of this.parts) {
          getScore += item.getScore
          deductScore += item.deductScore
        }
        return getScore - deductScore
      }
    },
    methods: {
      viewAnalysis() {
        this.$emit('view-analysis')
      },
      // 在考一次
      testAgain() {
        location.reload()
      },

      swipeTo(index) {
        this.$emit('swipeto', index, 1)
      }
    },
    created() {},
    mounted() {
      if (this.getEncourageAgain) {
        examService
          .getEncourage({ type: 1, point: this.rightRate })
          .then(res => {
            this.$emit('encourage', res.title)
          })
      }
    }
  }
})(window)
